<template>
	<view>
		<tabBar :currentPagePath="this.$route.meta.pagePath"></tabBar>
		<u-navbar title="待办案件">
			<view class="u-nav-slot" slot="left">
			</view>
		</u-navbar>
		<!-- 列表 -->
		<uniFlowCase ref="uniFlowCase" :caseList="caseList" :flowStatus="1" @showDetail="showDetail" emptyText="暂无待办案件">
		</uniFlowCase>
	</view>
</template>

<script>
	import uniFlowCase from '@/components/uniFlowCase/uniFlowCase.vue';
	import {
		queryMf_MyTaskUndoList,
		detailsBusinessList,
	} from '@/common/api/approve/workflow/mf_MyTasjUndo';
	import {
		Tp_proctypeValue
	} from '@/common/enumeration/Tp_proctype.js'
	import moment from 'moment';

	export default {
		data() {
			return {
				// 列表查询条件
				queryParam: {
					"userid": '',
					"bizenum": 1000,
					"statusapply": [6002900, 6002901, 6002903, 6002904],
					"isCorrelation": true,
					"pageNumber": 1,
					"pageSize": 10,
					"f_subprocess": []
				},
				// 待办案件
				caseList: [],
				// 用户信息
				user: {}
			};
		},
		async onLoad() {
			this.user = JSON.parse(sessionStorage.getItem("APPROVE_USER"))
			this.queryParam.userid = this.user.userid

			uni.showLoading({
				title: '加载中'
			})

			for (let key in Tp_proctypeValue) {
				this.queryParam.f_subprocess.push(Tp_proctypeValue[key])
			}

			await this.getTodoList()

			uni.hideLoading()

		},
		//加载更多
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);
			this.caseList = [],
				this.queryParam.pageNumber = 1
			this.getTodoList()
		},
		onReachBottom() {
			if (this.$refs.uniFlowCase.status == "normal") {
				return
			}
			this.$refs.uniFlowCase.status = "loading"
			this.queryParam.pageNumber++
			this.getTodoList()
		},
		methods: {
			showDetail(data) {
				let applyid = data.applyid
				let applyid_bs = data.applyid_bs
				let taskid = data.taskid
				let formid = data.formid
				let stepid = data.stepid
				let processinstanceid = data.processinstanceid
				uni.navigateTo({
					url: "/pages/approve/todo/todoDetail?applyid=" + applyid + "&taskid=" + taskid + "&formid=" +
						formid + "&applyid_bs=" + applyid_bs + "&stepid=" + stepid + "&processinstanceid=" +
						processinstanceid,
				});
			},
			//加载待办数据
			async getTodoList() {
				let res = await detailsBusinessList({
					userid: this.queryParam.userid
				}, this.queryParam)
				if (res.code == 0) {
					if (res.data.records && res.data.records.length) {
						this.caseList = this.caseList.concat(res.data.records)
						console.log(this.caseList);
						if (this.caseList.length == res.data.total) {
							this.$refs.uniFlowCase.status = "normal"
						} else {
							this.$refs.uniFlowCase.status = "loadmore"
						}
					} else {
						this.caseList = []
					}
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	page {
		background-color: #f5f5f5;
		margin-top: 6px;
	}
</style>